#!/usr/bin/evn python
# -*- coding: UTF-8 -*-
# @File: manual_input_member_page.py
# @Author: fy
# @date: 2021/9/7 10:08
from appium.webdriver.common.mobileby import MobileBy

from pages.base_page import BasePage
from time import sleep


class ManualInputMemberPage(BasePage):
    # 模拟器与真机id不一样
    # _name_input_locator = (MobileBy.ID, "com.tencent.wework:id/bf6")
    _name_input_locator = (MobileBy.XPATH, '//*[contains(@text, "姓名")]/following-sibling::android.widget.EditText')
    # _phone_input_locator = (MobileBy.ID, "com.tencent.wework:id/ge0")
    _phone_input_locator = (MobileBy.XPATH, '//*[contains(@text, "手机")]/following-sibling::*//android.widget.EditText')
    # _save_btn_locator = (MobileBy.ID, "com.tencent.wework:id/ana")
    _save_btn_locator = (MobileBy.XPATH, '//*[@text="保存"]')

    def save_input(self, name, phone):
        from pages.add_member_page import AddMemberPage
        '''
        输入点击保存
        :return: 
        '''
        self.find_and_input(self._name_input_locator, name)
        self.find_and_input(self._phone_input_locator, phone)
        self.find_and_click(self._save_btn_locator)
        return AddMemberPage(self.driver)

    def save_input_failed(self, name, phone):
        from pages.add_member_page import AddMemberPage
        '''
        输入点击保存失败
        :return: 弹框内容
        '''
        self.find_and_input(self._name_input_locator, name)
        self.find_and_input(self._phone_input_locator, phone)
        self.find_and_click(self._save_btn_locator)
        sleep(2)
        # print(self.driver.window_handles)
        # self.driver.switch_to.window(self.driver.window_handles[-1])
        page_source = self.driver.page_source
        ok_locator = (MobileBy.XPATH, '//*[@text="确定"]')
        self.find_and_click(ok_locator)
        self.driver.back()
        return  page_source
